﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class UIFailed : MonoBehaviour
{
    public GameObject top;
    public GameObject buttonRestart, buttonContinue;

    private void Awake()
    {
        top = transform.Find("BG").gameObject;
        UGUIEventListener.Get(buttonRestart).onClick = (obj) =>
        {
            Time.timeScale = 1;
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        };
        UGUIEventListener.Get(buttonContinue).onClick = (obj) =>
        {
            Time.timeScale = 1;
            GameController.instance.lastTimes = 1;
            Message m = new Message(MsgType.ReduceFeibiao);
            m.send();
            StopAllCoroutines();
            StartCoroutine(InitPlayer());
        };
    }

    IEnumerator InitPlayer()
    {
        yield return null;        
        if (GameController.instance.player != null) GameController.instance.player.GetComponent<Player>().Init();
        gameObject.SetActive(false);
    }

    private void Start()
    {
        HideAll();
    }

    public void Open()
    {
        top.GetComponent<TweenPosition>().enabled = true;
        top.GetComponent<TweenPosition>().PlayForward();
    }

    void HideAll()
    {
        top.GetComponent<TweenPosition>().ResetToBeginning();
    }
}